package com.joinval.stamp;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Optional;

/**
 * 该测试方法为签章平台接口调用通用方法，根据接口参数、地址相应调整即可
 */
public class downloadTest {
	public static String callbackUrl = "";

	public static void main(String[] args) throws Exception {
		ZWWW();
	}


	/**
	 * 政务外网下载文档
	 * 
	 * @throws Exception
	 */
	public static void ZWWW() throws Exception {
		String accessToken = "MZiKtq9dxe";
		String accessSecret = "T7eTnDFCCh8DMq3VQ3huymALFI3H1w";
		String url = "https://open-out.qiyuesuo.cn/document/download";
		HttpClient httpClient = new HttpClient(Optional.empty());

		String x_qys_timestamp = String.valueOf(System.currentTimeMillis());
		// 签名，对参数进行md5运算，转成16进制字符串：
		String x_qys_signature = MD5.toMD5(accessToken + accessSecret + x_qys_timestamp);

		// 拼接参数
		HttpParamers paramers = new HttpParamers(HttpMethod.GET);
		paramers.addParam("documentId", "2769147125780496843");

		// 添加请求头
		HttpHeader httpHeader = new HttpHeader();
		httpHeader.addProperty("x-qys-timestamp", x_qys_timestamp);
		httpHeader.addProperty("x-qys-signature", x_qys_signature);
		httpHeader.addProperty("x-qys-accesstoken", accessToken);
		File file2 = new File("/Users/chenkaihang/IdeaProjects/joinval-volunteer/src/main/resources/pdf/ZWWW131.pdf");
		FileOutputStream fo = new FileOutputStream(file2);
		httpClient.doDownload(url, paramers, httpHeader, fo);
		System.out.println("下载成功");
	}
}
